package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.annotation.RequireLogin;
import cn.wolfcode.wolf2w.annotation.UserParam;
import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.query.TravelCommentQuery;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.redis.service.IUserInfoRedisService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelCommentService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.util.UMEditorUploader;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("travels")//travels/query
public class TravelController {

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IUserInfoRedisService userInfoRedisService;

    @Autowired
    private ITravelCommentService travelCommentService;



    @GetMapping("/query")
    public Object query(TravelQuery qo) {
        return JsonResult.success(travelService.query(qo));
        }


//查询某个游记
    @GetMapping ("/detail")
    public Object detail(String id){
        return  JsonResult.success(travelService.detail(id));//如果成功了,就返回出成功的信息告诉用户,失败就返回获取抛出的异常信息(状态不对)
    }
//添加游记评论
    @PostMapping ("/commentAdd")
    public Object commentAdd(TravelComment comment,@UserParam UserInfo userInfo){

        travelCommentService.addComment(comment,userInfo);
        return  JsonResult.success();
    }
//查询某个游记评论
    @GetMapping ("/comments")
    public Object get(TravelCommentQuery qo){
        Page<TravelComment> page = travelCommentService.query(qo);
        return  JsonResult.success(page );
    }




}
